package com.hsgene.user.dto.user;

import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
import com.hsgene.common.util.date.TimeJsonDeserializer;
import com.hsgene.common.util.web.session.UserSession;
import com.hsgene.user.domain.User;
import com.hsgene.user.domain.UserClass;

import java.io.Serializable;
import java.util.Date;

/**
 * 用户信息DTO
 *
 * @author wangbing
 * @version 1.0, 2018/6/22
 */
public class UserDto implements Serializable {
    private static final long serialVersionUID = 5572025400981406475L;

    /**
     * 用户编号
     */
    private String userId;

    /**
     * 登录手机号，如果注册时使用的是账号名，则默认为账号名
     */
    private String phone;

    /**
     * 登录密码
     */
    private String password;

    /**
     * 昵称
     */
    private String nickName;

    /**
     * 头像
     */
    private String headImage;

    /**
     * 年龄(int)
     */
    private Short age;

    /**
     * 性别(int)：0 = 保密，1 = 男，2 = 女
     */
    private Byte gender;

    /**
     * 是否删除
     */
    private Boolean deleted;

    /**
     * 用户类型
     */
    private String userType;

    /**
     * 是否可用
     */
    private boolean available;

    /**
     * 创建人用户，如果等于userId，表示自主注册
     */
    private String creatorId;

    /**
     * 用户注册IP
     */
    private String registerIp;

    /**
     * 注册IP所在地
     */
    private String registerAddress;

    /**
     * 最近一次用户登录IP
     */
    private String lastLoginIp;

    /**
     * 最近一次用户登录IP所在地
     */
    private String lastLoginAddress;

    /**
     * 最近一次登录时间
     */
    @JsonDeserialize(using = TimeJsonDeserializer.class)
    private Date lastLoginTime;

    /**
     * 创建时间
     */
    @JsonDeserialize(using = TimeJsonDeserializer.class)
    private Date createTime;

    /**
     * 更新时间
     */
    @JsonDeserialize(using = TimeJsonDeserializer.class)
    private Date updateTime;

    /**
     * 用户会话信息
     */
    private UserSession userSession;

    public UserDto() {
    }

    public UserDto(User user, UserClass userClass) {
        this.userId = user.getId();
        this.phone = user.getPhone();
        this.nickName = user.getNickName();
        this.headImage = user.getHeadImage();
        this.age = user.getAge();
        this.gender = user.getGender();
        this.deleted = user.getDeleted();
        this.userType = userClass.getUserType();
        this.available = userClass.getAvailable();
        this.creatorId = userClass.getCreatorId();
        this.registerIp = userClass.getRegisterIp();
        this.registerAddress = userClass.getRegisterAddress();
        this.lastLoginIp = userClass.getLastLoginIp();
        this.lastLoginAddress = userClass.getLastLoginAddress();
        this.lastLoginTime = userClass.getLastLoginTime();
        this.createTime = userClass.getCreateTime();
        this.updateTime = userClass.getUpdateTime();
    }

    public String getUserId() {
        return userId;
    }

    public void setUserId(String userId) {
        this.userId = userId;
    }

    public String getPhone() {
        return phone;
    }

    public void setPhone(String phone) {
        this.phone = phone;
    }

    public String getPassword() {
        return password;
    }

    public void setPassword(String password) {
        this.password = password;
    }

    public String getNickName() {
        return nickName;
    }

    public void setNickName(String nickName) {
        this.nickName = nickName;
    }

    public String getHeadImage() {
        return headImage;
    }

    public void setHeadImage(String headImage) {
        this.headImage = headImage;
    }

    public Short getAge() {
        return age;
    }

    public void setAge(Short age) {
        this.age = age;
    }

    public Byte getGender() {
        return gender;
    }

    public void setGender(Byte gender) {
        this.gender = gender;
    }

    public Boolean getDeleted() {
        return deleted;
    }

    public void setDeleted(Boolean deleted) {
        this.deleted = deleted;
    }

    public String getUserType() {
        return userType;
    }

    public void setUserType(String userType) {
        this.userType = userType;
    }

    public boolean getAvailable() {
        return available;
    }

    public void setAvailable(boolean available) {
        this.available = available;
    }

    public String getCreatorId() {
        return creatorId;
    }

    public void setCreatorId(String creatorId) {
        this.creatorId = creatorId;
    }

    public String getRegisterIp() {
        return registerIp;
    }

    public void setRegisterIp(String registerIp) {
        this.registerIp = registerIp;
    }

    public String getRegisterAddress() {
        return registerAddress;
    }

    public void setRegisterAddress(String registerAddress) {
        this.registerAddress = registerAddress;
    }

    public String getLastLoginIp() {
        return lastLoginIp;
    }

    public void setLastLoginIp(String lastLoginIp) {
        this.lastLoginIp = lastLoginIp;
    }

    public String getLastLoginAddress() {
        return lastLoginAddress;
    }

    public void setLastLoginAddress(String lastLoginAddress) {
        this.lastLoginAddress = lastLoginAddress;
    }

    public Date getLastLoginTime() {
        return lastLoginTime;
    }

    public void setLastLoginTime(Date lastLoginTime) {
        this.lastLoginTime = lastLoginTime;
    }

    public Date getCreateTime() {
        return createTime;
    }

    public void setCreateTime(Date createTime) {
        this.createTime = createTime;
    }

    public Date getUpdateTime() {
        return updateTime;
    }

    public void setUpdateTime(Date updateTime) {
        this.updateTime = updateTime;
    }

    public UserSession getUserSession() {
        return userSession;
    }

    public void setUserSession(UserSession userSession) {
        this.userSession = userSession;
    }
}
